﻿/**
 * Created by xjchen on 2020-03-19.
 * */

#ifndef MIDDLEWARE_DEVICEWRITER_H
#define MIDDLEWARE_DEVICEWRITER_H


#include "BaseObject.h"

class OutputBuffer;

class Scheduler;

class WriteWorker;

class TaskModule;

class DeviceWriter : public BaseObject {
public:
    DeviceWriter();

    ~DeviceWriter();

    virtual int64_t onWrite(char *buffer, int64_t len) { return len; };

    /**
     * 将任务绑定在某个CPU核上运行
     * 对于NUMA设备，请在创建对象后立即调用此API，因为在其他API中实现的NUMA相关内存分配策略
     * 依据为此处设定的CPU核
     *
     * @param whichCore 绑定的CPU核
     */
    FLOW_API void bindCPUCore(int coreId);

    /** 可以在此建立连接 */
    virtual void setupConnection();

    virtual void start();

    virtual void stop();

    OutputBuffer *bufferRef = nullptr;
    WriteWorker *worker = nullptr;
protected:
    friend class Scheduler;

    friend class WriteWorker;

    friend class TaskModule;

    bool isBlocking = true;
    int64_t sequence = 0L;
};


#endif /** MIDDLEWARE_DEVICEWRITER_H */
